<template>
  <div>
    <el-form ref="editForm" :model="formFileds">
      <el-row :gutter="24">

        <el-col :span="12">
          <el-form-item>
            <el-input></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item>
            <el-button type="primary">
              查询
            </el-button>

            <el-button type="primary" @click="add()">
              增加
            </el-button>

          </el-form-item>
        </el-col>

      </el-row>


    </el-form>
    <!--表格内容-->
    <el-table ref="list" :data="tableData" style="width: 100%;margin-bottom: 5=1px;" border stripe highlight-current-row
      :default-sort="{ prop: 'date', order: 'descending' }">
      <!-- v-for="item in tableData" v-bind:key="item.index" -->
      <el-table-column fixed type="selection" width="45">
      </el-table-column>
      <el-table-column property="name" label="企业名称" align="center">
      </el-table-column>
      <el-table-column property="username" label="企业账号" align="center">
      </el-table-column>
      <el-table-column property="sf" label="省份" align="center">
      </el-table-column>
      <el-table-column property="szcs" label="所在城市" align="center">
      </el-table-column>
      <el-table-column property="qydh" label="联系电话" align="center">
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" width="350" >
        <template slot-scope="scope">
          <el-button type="success" size="mini" @click="passwordChange()">重置密码</el-button>
          <el-button type="success" size="mini" @click="phoneChange()">变更手机号</el-button>
          <el-button type="primary" @click="Compile()" size="mini">编辑</el-button>
          <el-button type="danger" title="删除" size="mini" @click="rowDel(scope.$index, scope.row, $event)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination :page-sizes="[10, 20, 30, 40, 100]" :page-size=this.pageSize :total=this.total :current-page="currentPage" 
    layout="total, sizes, prev, pager, next, jumper" @current-change="getCurrentPage" @size-change="getSize">
    </el-pagination>

    <Add v-if="isShowAddDialog" :isShowAddDialog="isShowAddDialog" @dialogClose="dialogClose"></Add>
    <Compile v-if="isShowComDialog" :isShowComDialog="isShowComDialog" @dialogClose="dialogClose"></Compile>
    <Password v-if="isShowPasswordDialog" :isShowPasswordDialog="isShowPasswordDialog" @dialogClose="dialogClose"></Password>
    <Phone v-if="isShowPhoneDialog" :isShowPhoneDialog="isShowPhoneDialog" @dialogClose="dialogClose"></Phone>
  </div>
</template>
   
<script>
import Add from "./enterpriseManageAdd.vue";
import Compile from "./enterpriseManagecompile.vue";
import Password from "./passwordChange.vue";
import Phone from "./phoneChange.vue";
import { getAll } from "@/api/accountManage/enterprise";
export default {
  name: "Table",
  components: {
    Add,
    Compile,
    Password,
    Phone
  },
  data() {
    return {
      pageSize: 10,
      total: 0,
      currentPage: 1,
      param: '',
      qyid:2,
      formFileds: {
        text: '',
        param: ''
      },
      tableData: [
        {
          index: 0,
          firmName: "金汉斯集团",
          firmNumber: "JHS890511",
          province: "湖南省",
          city: "长沙",
          phone: "17309998201",

        }, 
      ],
      isShowAddDialog:false,
      isShowComDialog:false,
      isShowPhoneDialog:false,
      isShowPasswordDialog:false,
    }
  },
  methods: {
    rowEdit(row) {
      // //当前选中行
      this.formFileds = row;
    },
    dialogClose() {
      this.isShowEditDialog = false;
      this.isShowAddDialog = false;
      this.isShowComDialog = false;
      this.isShowPasswordDialog = false;
      this.isShowPhoneDialog = false;
    },
    handleEdit(id) {
      this.$refs.editForm.validate(isValid => {

        if (!isValid) return;

        // 保存编辑后的数据
        Object.assign(this.tableData[id], this.formFileds);
        this.isShowEditDialog = false;

        // 考虑到可能编辑了日期-需要重新排序
        // ***注意：手动排序传参和表格的default-sort属性格式不太一样
        this.$refs.list.sort('date', 'descending');

        this.$message.success('编辑成功');
      });
    },
    add() {
      this.isShowAddDialog = true;
    },
    Compile() {
      this.isShowComDialog = true;
    },
    passwordChange(){
      this.isShowPasswordDialog = true;
    },
    phoneChange(){
      this.isShowPhoneDialog = true;
    },
    
    rowDel(row, event) {

      // 让当前删除按钮失焦
      event.target.blur();

      this.$confirm('确定要删除当前行吗？', '删除', {
        comfirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(() => {

        this.tableData.splice(row.id, 1);
        this.$message.success('删除成功');
        return false;
      });
    },
    // 选中当前行-当前行的复选框被勾选
    setCurRowChecked(row) {

      this.$refs.list.clearSelection();
      this.$refs.list.toggleRowSelection(row);
    },
    getCurrentPage(currentPage){
      // console.log(currentPage);
      this.currentPage = currentPage;
      this.getList();
    },
    getSize(pageSize){
      // console.log(pageSize);
      this.pageSize = pageSize;
      this.getList();
    },
    getList(){
      this.param = 'input=' + this.qyid;
      getAll(this.param).then((res) => {
        if(res){
          console.log(res);
          // this.total = res.data.total;
          // this.tableData = res.data.list;
          this.tableData = res.data;
        }
      })
    },
  },
  mounted(){
    this.getList();
  }
}
</script>
  
<style scoped lang="less">
.el-form {
  padding: 0 10px;
}

.el-date-editor {
  width: 100% !important;
}
</style>
  